<?php $this->load->view('layout/header');?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">旅游产品<small> 商品列表</small></h3>
            <?php echo breadcrumb(array('tourismgoods/grid'=>'旅游产品', 'tourismgoods/grid'=>'商品列表')); ?>
        </div>
    </div>
    <?php echo execute_alert_message() ?>
    <div class="row-fluid">
        <div class="span12">
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-search"></i>搜索</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form class="form-horizontal form-search" action="<?php echo base_url('tourismgoods/grid') ?>" method="get">
                        <div class="row-fluid">
                            <div class="span5">
                                <div class="control-group">
                                    <label class="control-label">商品搜索</label>
                                    <div class="controls">
                                        <input type="text" name="goods_search" value="<?php echo $this->input->get('goods_search');?>" class="m-wrap span12" placeholder="请输入商品名称">
                                    </div>
                                </div>
                            </div>
                            <div class="span7">
                                <div class="control-group">
                                    <label class="control-label">供应商</label>
                                    <div class="controls">
                                        <input type="text" name="username" value="<?php echo $this->input->get('username');?>" class="m-wrap span8" placeholder="请输入供应商帐号或别名或UID">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span5">
                                <div class="control-group">
                                    <label class="control-label">审核状态</label>
                                    <div class="controls">
                                        <select name="is_check" class="m-wrap span12">
                                            <option value="">请选择</option>
                                            <?php foreach ($is_check as $kk=>$vv):?>
                                            <option value="<?php echo $kk;?>" <?php if ($this->input->get('is_check')==$kk):?>selected="selected"<?php endif;?>><?php echo $vv;?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="span7">
                                <div class="control-group">
                                    <label class="control-label">上下架</label>
                                    <div class="controls">
                                        <select name="is_on_sale" class="m-wrap span8">
                                            <option value="">请选择</option>
                                            <option value="1" <?php if($this->input->get('is_on_sale')==1){echo 'selected';}?> >上架</option>
                                            <option value="2" <?php if($this->input->get('is_on_sale')==2){echo 'selected';}?>>下架</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span5">
                                <div class="control-group">
                                    <label class="control-label">位置推荐</label>
                                    <div class="controls">
                                        <select name="show_flag" class="m-wrap span12">
                                            <option value="">请选择</option>
                                            <?php foreach ($show_flag as $key=>$value):?>
                                            <option value="<?php echo $key;?>" <?php if ($this->input->get('show_flag')==$key):?>selected="selected"<?php endif;?>><?php echo $value;?></option>
                                            <?php endforeach;?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="span7">
                                <div class="control-group">
                                    <label class="control-label">省/市/区</label>
                                    <div class="controls">
                                        <?php $this->load->view('commonhtml/districtSelect');?>
                                    </div>
                                </div>
                            </div>
                        </div>
                       <div class="row-fluid">                      
                            <div class="span5">
                                <div class="control-group">
                                    <label class="control-label">分类</label>
                                    <div class="controls">
                                        <?php $this->load->view('commonhtml/categorySelect');?>
                                    </div>
                                </div>
                            </div>
                            <div class="span5">
                                <div class="control-group">
                                    <label class="control-label">商品ID</label>
                                    <div class="controls">
                                        <input type="text" name="goods_attr_id" value="<?php echo $this->input->get('goods_attr_id');?>" class="m-wrap span12" placeholder="请输入商品ID">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row-fluid">
                            <div class="span5">
                                <div class="control-group">
                                    <label class="control-label">开始时间</label>
                                    <div class="controls">
                                        <div class="input-append date form_datetime">
                                            <input type="text" class="m-wrap m-ctrl-medium" size="16" name="start_date" value="<?php echo $this->input->get('start_date');?>">
                                            <span class="add-on"><i class="icon-calendar"></i></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="span7">
                                <div class="control-group">
                                    <label class="control-label">结束时间</label>
                                    <div class="controls">
                                        <div class="input-append date form_datetime">
                                            <input type="text" class="m-wrap m-ctrl-medium" size="16" name="end_date" value="<?php echo $this->input->get('end_date');?>">
                                            <span class="add-on"><i class="icon-calendar"></i></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions">
                            <button class="btn green" type="submit">搜索</button>
                            <button class="btn reset_button_search" type="button">重置条件</button>
                            <button class="btn blue" type="submit" name="excel" value="excel" >导出excel</button>
                        </div>
                    </form>
                </div>
            </div>
            <div class="portlet box green">
                <div class="portlet-title">
                    <div class="caption"><i class="icon-reorder"></i>列表</div>
                    <div class="tools">
                        <a class="collapse" href="javascript:;"></a>
                        <a class="remove" href="javascript:;"></a>
                    </div>
                </div>
                <div class="portlet-body flip-scroll">
                    <div class="dataTables_wrapper form-inline">
                        <div class="row-fluid scebery-order-pagination">
                            <span class="dataTables_info">
                                <span>当前第</span><span style="color: red"><?php echo $pg_now?></span>页 
                                <span>共</span><span style="color: red"><?php echo $all_rows?></span>条数据
                                <span>每页显示20条 </span>
                                <?php echo $pg_list ?>
                            </span>
                            <span class="scebery-order-find">
                                <input type="text" name="pg" value="<?php echo isset($pg_now) ? $pg_now :'';?>" class="m-wrap small" placeholder="请输入页数">
                                <button type="button" class="btn green">确定</button>
                                <button type="button" class="btn green" onclick="window.location.href=localtion.href">刷新</button>
                                
                                <a type="button" class="btn red up" flag="1" pg="<?php echo isset($pg_now) ? $pg_now :'1';?>">上架</a>
                                <a type="button" class="btn red down" flag="2" pg="<?php echo isset($pg_now) ? $pg_now :'1';?>">下架</a>
                                <a type="button" class="btn yellow agree" flag="3" pg="<?php echo isset($pg_now) ? $pg_now :'1';?>">审核通过</a>
                                <a type="button" class="btn yellow reject" flag="4" pg="<?php echo isset($pg_now) ? $pg_now :'1';?>">审核拒绝</a>
                                <a type="button" class="btn yellow logic-delete" flag="5" pg="<?php echo isset($pg_now) ? $pg_now :'1';?>">删除</a>
                                <a href="<?php echo base_url('tourismgoods/addstep1');?>">
                                    <button type="button" class="btn green"><i class="icon-plus"></i> 添加</button>
                                </a>
                            </span>
                        </div>
                        <?php if ($line_list->num_rows()>0) :?>
                        <table class="table table-striped table-bordered table-hover" id="sample_1">
                            <thead class="flip-content">
                                <tr>
                                    <th width="15"><input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"></th>
                                    <th>商品id</th>
                                    <th>商品名称</th>
                                    <th>供应商</th>
                                    <th>省/市/区</th>
                                    <th>价格</th>
                                    <th>库存</th>
                                    <th>审核状态</th>
                                    <th>自营</th>
                                    <th>上下架</th>
                                    <th>删除</th>
                                    <th>更新时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($line_list->result() as $item): ?>
                                <tr>
                                    <th><input type="checkbox" class="checkboxes goods_attr" name="goods_attr"  value="<?php echo $item->goods_attr_id;?>"  goods_id="<?php echo $item->goods_id;?>"></th>
                                    <td><?php echo $item->goods_attr_id ?></td>
                                    <td width="150">
                                        <?php echo ($item->goods_native==2 ? '<strong>【特产】</strong>' : '').$item->goods_name ?>
                                    </td>
                                    <td>
                                        <?php echo $item->user_name;?><p></p>
                                        <?php echo $item->alias_name ?>
                                    </td>
                                    <td>
                                        <?php echo !empty($item->province_id) ? $all_region[$item->province_id]['region_name'] : $item->province_id;?>
                                        <?php echo !empty($item->city_id) ? '/'.$all_region[$item->city_id]['region_name'] : $item->city_id;?>
                                        <?php echo !empty($item->district_id) ? '/'.$all_region[$item->district_id]['region_name'] : $item->district_id;?>
                                    </td>
                                    <td>
                                        <p>售：<?php echo $item->shop_price ?></p>
                                        <p>供：<?php echo $item->supply_price ?></p>
                                    </td>
                                    <td><?php echo $item->goods_num ?></td>
                                    <td style="width:95px">
                                        <?php if ($item->is_check == 1) :?>
                                            <?php echo $is_check[$item->is_check];?><br />
                                            <a class="btn mini green" href="<?php echo base_url('tourismgoods/setIsCheckStatus/'.$item->goods_attr_id.'/'.$item->is_check.'/'.$pg_now).'?'.$_SERVER['QUERY_STRING'];?>" onclick="return confirm('确定要审核通过？')">通过</a>
                                            <a class="btn mini green" href="<?php echo base_url('tourismgoods/setIsCheckStatus/'.$item->goods_attr_id.'/2/'.$pg_now).'?'.$_SERVER['QUERY_STRING'];?>" onclick="return confirm('确定要审核拒绝？')">拒绝</a>
                                        <?php else :?>
                                            <?php echo $is_check[$item->is_check];?>
                                        <?php endif;?>
                                    </td>
                                    <td width="45">
                                        <?php echo $item->is_beizhu ==1 ? '是' : '否';?>
                                    </td>
                                    <td width="45">
                                        <a class="btn mini green" href="<?php echo base_url('tourismgoods/setIsOnSaleStatus/'.$item->goods_id.'/'.$item->is_on_sale.'/'.$pg_now).'?'.$_SERVER['QUERY_STRING'];?>" onclick="return confirm('确定要<?php echo $item->is_on_sale==1?'下架':'上架'?>？')">
                                            <?php echo $item->is_on_sale==1?'上架':'下架';?>
                                        </a>
                                    </td>
                                    
                                    <td width="45">
                                        <a class="btn mini green" href="<?php echo base_url('tourismgoods/setIsLogicDelete/'.$item->goods_attr_id.'/'.$item->logic_delete.'/'.$pg_now).'?'.$_SERVER['QUERY_STRING'];?>" onclick="return confirm('确定要<?php echo $item->logic_delete==1?'逻辑删除':'恢复'?>？')">
                                            <?php echo $item->logic_delete==1?'未删':'已删';?>
                                        </a>
                                    </td>
                                    <td><?php echo $item->updated_at ?></td>
                                    <td width="145">
                                        <a class="btn mini green" href="<?php echo base_url('tourismgoodsbargaining/grid?goods_attr_id='.$item->goods_attr_id) ?>">议价管理</a>
                                        <p></p>
                                        <a class="btn mini green" href="<?php echo base_url('tourismgoods/edit/'.$item->goods_attr_id) ?>">编辑</a>
                                        <a class="btn mini green" href="<?php echo base_url('tourismgoods/copy/'.$item->goods_attr_id) ?>">复制</a>
                                        <p></p>
                                        <a target="_blank" class="btn mini green" href="<?php echo $this->config->wap_base_url.'tourism/goods/preview/'.$item->goods_attr_id.'.html'?>">移动端预览</a>
                                    </td>
                                </tr>
                                <?php endforeach;?>
                            </tbody>
                        </table>
                        <div class="row-fluid">
                            <span class="dataTables_info">
                                <span>当前第</span><span style="color: red"><?php echo $pg_now ?></span>页
                                <span>共</span><span style="color: red"><?php echo $all_rows ?></span>条数据
                                <span>每页显示20条 </span>
                                <?php echo $pg_list ?>
                            </span>
                            <span class="scebery-order-find">
                                <input type="text" name="pg" value="<?php echo isset($pg_now) ? $pg_now :'';?>" class="m-wrap small" placeholder="请输入页数">
                                <button type="button" class="btn green">确定</button>
                                <button type="button" class="btn yellow" onclick="localtion.href=localtion.href">刷新</button>
                            </span>
                        </div>
                        <?php else : ?>
                            <div class="alert"><p>未找到数据。<p></div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" >
$(function(){
	
   $('.scebery-order-find  button').click(function(){
       var pg = $(this).parents('.scebery-order-find').find('input[name="pg"]').val();
       if (pg.length==0) {
   	       return false;
       }
       window.location.href="<?php echo base_url('tourismgoods/grid')?>"+"/"+pg+"<?php echo isset($url) ? $url :'';?>";
   })

   $('.scebery-order-find').delegate('.up,.down,.agree,.reject,.logic-delete','click',function(e){
	   var id = [];
	   var goodsId = [];
	   var type = $(this).attr('flag');
	   var pg = $(this).attr('pg');
	   var _this = $(this);
       $('.goods_attr:checked').each(function(i){
      	   id[i] = $(this).val();
           goodsId[i] = $(this).attr('goods_id');
       })
       if (id.length==0 || goodsId.length==0) {
   	       return alert('请选择产品');
       }
       $.ajax({
    	   type: 'post',
           async: true,
           dataType: 'json',
           url: hostUrl() + '/tourismgoods/batchSetStatus',
           data: {type:type,pg:pg,id:id,goodsId:goodsId},
           beforeSend:function(){
        	   _this.text('操作中').attr("disabled",true);
           },
           success: function (data) {
               if (data.status) {
                   $('.alert-error').hide();
                   window.location.href = data.messages;
               } else {
                   $('.alert-error').show();
                   $('.alert-error .remove_2 p').html(data.messages);
                   var body = (window.opera) ? (document.compatMode == 'CSS1Compat' ? $('html') : $('body')) : $('html,body');
                   body.animate({scrollTop: $('.page-container').offset().top}, 1000);
                   _this.text('请重新操作').attr("disabled",false);
               }
           }
       })
   })
});
</script>
<?php $this->load->view('layout/footer');?>